package wqh.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import wqh.domain.Device;

import java.util.List;

/**
 * Created by devts on 2016/9/25.
 */
public interface DeviceDao {

    @Select("select * from device")
    List<Device> findAllRecord();

    @Select(("select * from device where name = #{1}"))
    List<Device> findRecordByName(String name);


    Device findAllByID(Integer id);

    @Select("select * from device where name = #{0} and ip = #{1}")
    List<Device> findAllByNameAndIP(String name, Integer ip);

    @Insert("INSERT INTO device (name, ip, status, description, phone) VALUES (#{name}, #{ip}, #{status}, #{description}, #{phone}) ")
    int insertRecord(Device device);

    @Update("UPDATE device SET name = #{name}, ip = #{ip}, status = #{status}, description = #{description}, phone = #{phone} WHERE id = #{id}")
    int updateRecord(Device device);

    @Delete("DELETE FROM device WHERE id = #{1}")
    int deleteRecord(Integer id);

    @Select("SELECT name FROM device WHERE id = #{1}")
    String findNameById(Integer id);

    @Select("SELECT * FROM device WHERE ip = #{1}")
    Device findAllByIp(Integer ip_int);

    List<Device> findByIp(Integer ip);


}
